package com.zhihesj.anan.quartz.controller;

import com.zhihesj.anan.quartz.config.MyQuartzScheduler;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author anan.
 * @version 1.0
 * @create 2020-10-30 10-57
 */
@RestController
@RequestMapping("/quartz")
public class QuartzApiController {

    @Autowired
    private MyQuartzScheduler myQuartzScheduler;

    @RequestMapping("/start")
    public void startQuartzJob(){
        try {
            myQuartzScheduler.startJob();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/info")
    public String getQuartzJob(String name, String group) {
        String info=null;
        try {
            info = myQuartzScheduler.getJobInfo(name, group);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        return  info;
    }

    @RequestMapping("/modify")
    public boolean modifyQuartzJob(String name,String group,String time){
        boolean flag=true;
        try {
            flag = myQuartzScheduler.modifyJob(name, group, time);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
        return flag;
    }

    @RequestMapping("/pause")
    public void pauseQuartzJob(String name,String group){
        try {
            myQuartzScheduler.pauseJob(name, group);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/pauseAll")
    public void pauseAllQuartzJob(){
        try {
            myQuartzScheduler.pauseAllJob();
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("/delete")
    public void deleteJob(String name,String group){
        try {
            myQuartzScheduler.deleteJob(name, group);
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
